package com.bridgeintelligent.tag.customer.controller;

import com.bridgeintelligent.tag.customer.entity.AnalysisSetup;
import com.bridgeintelligent.tag.customer.entity.Result;
import com.bridgeintelligent.tag.customer.service.IAnalysisQuerySetupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "探查分析设置管理")
@AllArgsConstructor
@RestController
@RequestMapping("/api/querysetup")
@Slf4j
public class AnalysisQuerySetupController {

    private IAnalysisQuerySetupService querySetupService;

    @ApiOperation("新增探查分析设置")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "setup", value = "分析设置信息")
    })
    @PostMapping("/add")
    public Result addQuerySetup(@RequestBody AnalysisSetup setup) {
        try {
            querySetupService.add(setup);
            return new Result(0,"保存成功");
        } catch (Exception e) {
            log.error("保存失败：{}::"+e);
            return new Result(-1,"保存失败");
        }
    }


    @ApiOperation("修改探查分析设置")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "body", name = "setup", value = "分析设置信息")
    })
    @PostMapping("/update")
    public Result updateQuerySetup(@RequestBody AnalysisSetup setup) {
        try {
            querySetupService.update(setup);
            return new Result(0,"修改成功");
        } catch (Exception e) {
            log.error("修改失败：{}::"+e);
            return new Result(-1, "修改失败");
        }
    }

    @ApiOperation("根据ID删除分析设置")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "分析ID")})
    @GetMapping("/delById")
    public Result delQueryById(String id) {
        try {
            querySetupService.delById(id);
            return new Result(0,"删除成功");
        }catch (Exception e){
            log.error("删除失败：{}::"+e);
            return new Result(-1,"删除失败");
        }

    }

    @ApiOperation("根据TpId删除分析设置")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "tpId", value = "探查ID")})
    @GetMapping("/delByTpId")
    public Result delQueryByTpId(String tpId) {
        try {
            querySetupService.delByTpId(tpId);
            return new Result(0,"删除成功");
        }catch (Exception e){
            log.error("删除失败：{}::"+e);
            return new Result(-1,"删除失败");
        }

    }

    @ApiOperation("查看探查分析设置详情")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "分析ID")
    })
    @GetMapping("/findById")
    public Result findQueryById(String id) {
        try {
            AnalysisSetup setup = querySetupService.findById(id);
            return new Result(0,"查询成功",setup);
        }catch (Exception e){
            log.error("查看详情失败：{}::"+e);
            return new Result(-1,"查看详情失败");
        }
    }

    @ApiOperation("根据探查ID查询分析设置列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "tpId", value = "探查ID")
    })
    @GetMapping("/findByTpId")
    public Result findQueryByTpId(String tpId) {
        try {
            List<AnalysisSetup> list = querySetupService.findList(tpId);
            return new Result(0,"查询成功",list);
        }catch (Exception e){
            log.error("查询失败：{}::"+e);
            return new Result(-1,"查询失败");
        }
    }
}